package cn.ld.module.system.dal.mapper.permission;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.dataobject.BaseEntity;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.permission.vo.role.RolePageInVO;
import cn.ld.module.system.dal.entity.permission.RoleEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.lang.Nullable;

import java.util.Collection;
import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapperX<RoleEntity> {

    default PageResult<RoleEntity> selectPage(RolePageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<RoleEntity>()
                .likeIfPresent(RoleEntity::getName, inVO.getName())
                .likeIfPresent(RoleEntity::getCode, inVO.getCode())
                .eqIfPresent(RoleEntity::getStatus, inVO.getStatus())
                .betweenIfPresent(BaseEntity::getCreateTime, inVO.getCreateTime())
                .orderByAsc(RoleEntity::getSort));
    }

    default RoleEntity selectByName(String name) {
        return selectOne(RoleEntity::getName, name);
    }

    default RoleEntity selectByCode(String code) {
        return selectOne(RoleEntity::getCode, code);
    }

    default List<RoleEntity> selectListByStatus(@Nullable Collection<Integer> statuses) {
        return selectList(RoleEntity::getStatus, statuses);
    }

}
